package tools;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.Charset;

public class Message {
	public static void SendCommand(String cmd, OutputStream out) {
		byte[] b = cmd.getBytes(Charset.forName("UTF-8"));
		try {
			out.write(b);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	public static String ReadCommand(InputStream in)
	{
		byte[] b = new byte[255];
		String finalString = "";
		try {
			while (in.read(b, 0, 255) > 0)
			{
				finalString += new String(b, Charset.forName("UTF-8"));
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		return finalString;
	}
	public static Enum<?> GetCommand(String cmd)
	{
		switch (cmd.substring(5, 7)) {
		case "VER":
			return Command.VER;
		default:
			return Command.UWN;
		}
	}
	public enum Command
	{
		UWN,
		VER
	}
}
